package com.javacoo.xservice.base.support.auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import com.javacoo.xkernel.spi.ExtensionLoader;
import com.javacoo.xservice.base.support.auth.config.AuthConfig;

import lombok.extern.slf4j.Slf4j;

/**
 * 授权服务接口工厂
 * <li></li>
 *
 * @author: duanyong@jccfc.com
 * @since: 2021/3/16 8:56
 */
@Slf4j
@Component
@ConditionalOnBean(AuthConfig.class)
public class AuthServiceFactory {
    /** 授权服务配置 */
    @Autowired
    private AuthConfig authConfig;

    @Bean
    public AuthService createAuthService() {
        log.info("初始化授权服务,实现类名称:{}",authConfig.getImpl());
        AuthServiceHolder.authService = ExtensionLoader.getExtensionLoader(AuthService.class).getExtension(authConfig.getImpl());
        log.info("初始化授权服务成功,实现类:{}",AuthServiceHolder.authService);
        return AuthServiceHolder.authService;
    }
}
